package com.gruppsex.trainingdairy;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class ActivityDesc extends Activity {
	EditText cal;
	EditText km;
	EditText reps;
	EditText sets;
	EditText time;
	EditText weight;
	EditText desc;
	TextView act;
	int id;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		overridePendingTransition(R.anim.fadein, R.anim.fadeout);
		setContentView(R.layout.activitydesc);
		cal = (EditText) findViewById(R.id.et_desc_calories);
		km = (EditText) findViewById(R.id.et_desc_km);
		reps = (EditText) findViewById(R.id.et_desc_reps);
		sets = (EditText) findViewById(R.id.et_desc_sets);
		time = (EditText) findViewById(R.id.et_desc_time);
		weight = (EditText) findViewById(R.id.et_desc_weight);
		desc = (EditText) findViewById(R.id.et_desc_activitydesc);
		act = (TextView) findViewById(R.id.tv_desc_activity);
		cal.setText("0");
		km.setText("0");
		reps.setText("0");
		sets.setText("0");
		time.setText("0");
		weight.setText("0");
		desc.setHint("Add description");
		Bundle extras = getIntent().getExtras();
		act.setText(extras.getString("Activity.daypass"));
		id = extras.getInt("Activity.ID");

	}

	public void buttonClick(View v) {
		switch (v.getId()) {
		case R.id.desc_save_button:

			String strCal = cal.getText().toString();
			String strKm = km.getText().toString();
			String strReps = reps.getText().toString();
			String strSets = sets.getText().toString();
			String strTime = time.getText().toString();
			String strWeight = weight.getText().toString();
			String strDesc = "";

			if (desc.getText().toString() != null) {
				strDesc = desc.getText().toString();
			}
			String activity = act.getText().toString();
			int iCal = 0;
			int iKm = 0;
			int iReps = 0;
			int iSets = 0;
			int iTime = 0;
			int iWeight = 0;
			if (!strCal.equals("")) {
				iCal = Integer.parseInt(strCal);
			}
			if (!strKm.equals("")) {
				iKm = Integer.parseInt(strKm);
			}
			if (!strReps.equals("")) {
				iReps = Integer.parseInt(strReps);
			}
			if (!strSets.equals("")) {
				iSets = Integer.parseInt(strSets);
			}
			if (!strTime.equals("")) {
				iTime = Integer.parseInt(strTime);
			}
			if (!strWeight.equals("")) {
				iWeight = Integer.parseInt(strWeight);
			}
			try {
				DataBaseHelper dbHelper = new DataBaseHelper(this);
				dbHelper.openDataBase();
				//Sending 1 to notify database that the activity has been updated and not to get it again
				dbHelper.createDescEntry(activity, iCal, iKm, iReps, iSets,
						iTime, iWeight, 1, id, strDesc);
				dbHelper.close();
			} catch (Exception e) {
			}
			finish();
			break;
		}
	}
}
